package demo100;

import java.util.HashMap;
import java.util.Map;

public class twoSum {
    public int[] twoSum(int[] nums, int target) {
        Map<Integer,Integer> hash = new HashMap<>();
        for(int i = 0;i < nums.length;i++) {
            if(hash.containsKey(target-nums[i])) {
                return new int[]{hash.get(target-nums[i]),i};
            }
            hash.put(nums[i],i);
        }
        return new int[2];
    }
    public int[] twoSum1(int[] nums, int target) {
        int n = nums.length;

        int[] ret = new int[2];
        for(int i = 0;i < n;i++) {
            for(int j = i+1;j < n;j++) {
                if(nums[i]+nums[j] == target) {
                    ret[0]=i;
                    ret[1]=j;
                    break;
                }
            }
        }
        return ret;
    }
}
